package com.bus.common.web;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfigWebFilter {

	@Bean
	public FilterRegistrationBean processTimeFilter() {
		FilterRegistrationBean regist = new FilterRegistrationBean();
		regist.setName("processTime");
		regist.setFilter(processTime());
		regist.addUrlPatterns("*.jspx");
		regist.addUrlPatterns("*.jhtml");
		regist.addUrlPatterns("*.htm");
		return regist;
	}

	@Bean
	public ProcessTimeFilter processTime() {
		return new ProcessTimeFilter();
	}

	@Bean
	public FilterRegistrationBean xssFilter() {
		FilterRegistrationBean regist = new FilterRegistrationBean();
		regist.setName("XssFilter");
		regist.setFilter(xss());
		regist.addInitParameter("excludeUrls", "/member@/api");
		regist.addUrlPatterns("*.jsp");
		regist.addUrlPatterns("*.jspx");
		regist.addUrlPatterns("*.jhtml");
		regist.addUrlPatterns("*.html");
		regist.addUrlPatterns("*.htm");
		return regist;
	}

	@Bean
	public XssFilter xss() {
		return new XssFilter();
	}

}
